package com.das.mechanic_alone.mvp.view.alone.fragment;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import com.das.mechanic_alone.R;
import com.das.mechanic_alone.R2;
import com.das.mechanic_base.base.X3BaseFragment;
import com.das.mechanic_base.base.X3BasePresenter;
import com.zyyoona7.wheel.WheelView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class X3MileSetValueFragment extends X3BaseFragment {

    @BindView(R2.id.et_input)
    EditText et_input;
    @BindView(R2.id.tv_unit)
    TextView tv_unit;
    @BindView(R2.id.tv_notice)
    TextView tv_notice;
    @BindView(R2.id.wv_mile)
    WheelView<Integer> wv_mile;
    private List<Integer> mList;

    @Override
    protected int getLayoutId() {
        return R.layout.x3_fragment_mile_set_value;
    }

    @Override
    protected void initView(View view) {
        initMiles();

    }


    private void initMiles() {
        mList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            mList.add(i * 100);
        }

        for (int i = 1; i < 100; i++) {
            mList.add(i * 1000);
        }

        for (int i = 10; i <= 100; i++) {
            mList.add(i * 10000);
        }

        wv_mile.setData(mList);
        wv_mile.setOnItemSelectedListener((wheelView, data, position) -> {

//            if (data <= currentMiles) {
//                wv_num.setSelectedItemPosition(currentIndex);
//                et_input.setText(currentMiles + "");
//                et_input.setSelection(et_input.getText().toString().length());
//                tv_show.setText(mContext.getString(R.string.current_all_miles));
//                return;
//            }else {
//                et_input.setText(data + "");
//                et_input.setSelection(et_input.getText().toString().length());
//            }
//
//            /**
//             * 需要计算时间
//             */
//            int afterDay = (int) ((data - modifyBean.getCurrentMiles()) / modifyBean.getPerMiles());
//
//            if (afterDay < 0) {
//                int currentMiles = (int) modifyBean.getCurrentMiles();
//                int i = mList.indexOf(currentMiles);
//                if (i > 0) {
//                    wv_num.setSelectedItemPosition(i);
//                    return;
//                }
//            }else if (afterDay == 0) {
//                tv_show.setTextColor(Color.parseColor("#F64458"));
//                tv_show.setText(mContext.getString(R.string.now_to_work));
//            }else {
//                String addDaysMonth = DateUtils.getAddDaysMonth(afterDay);
//                tv_show.setTextColor(Color.parseColor("#666666"));
//                tv_show.setText(String.format(mContext.getString(R.string.schedule_time),addDaysMonth));
//            }
        });
    }

    @Override
    protected X3BasePresenter createPresenter() {
        return null;
    }

    @OnClick(R2.id.rl_input)
    public void onViewClick(View view) {
        if (view.getId() == R.id.rl_input) {// 调起软键盘
            InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(et_input, 0);
        }
    }

}
